import request from "../util/request.ts";
import { Permission} from "./type/model.ts";



export const fetchPermissionTree = async (): Promise<any> => {
    return await request.get(`/permission/tree`);
}

export const fetchPermissionMenu = async (): Promise<any> => {
    return await request.get(`/permission/menu`);
}

/**
 * 分页查询权限列表
 * @param currentPage 当前页码
 * @param pageSize 每页大小
 * @param permission 查询条件
 * @param during 时间范围
 * @returns 权限列表及分页信息
 */
export const fetchPermissionPage = async (currentPage: number, pageSize: number, permission: Permission, during: []): Promise<any> => {
    return await request.get(`/permission/page`, {
        params: {
            currentPage,
            pageSize,
            permission: JSON.stringify(permission),
            during: during.join(',')
        }
    });
}

/**
 * 添加权限
 * @param permission 权限对象
 * @returns 添加结果
 */
export const postPermission = async (permission: Permission): Promise<any> => await request.post("/permission", permission);

/**
 * 更新权限
 * @param permission 权限对象
 * @returns 更新结果
 */
export const putPermission = async (permission: Permission): Promise<any> => await request.put("/permission", permission);

/**
 * 删除权限
 * @param id 权限 ID
 * @returns 删除结果
 */
export const delPermission = async (id: number): Promise<any> => await request.delete(`/permission/${id}`);

/**
 * 批量删除权限
 * @param ids 权限 ID 数组
 * @returns 删除结果
 */
export const batchDelPermission = async (ids: number[]): Promise<any> => await request.delete(`/permission/batch/delete`, {
    params: {
        ids: ids.join(',')
    }
});

/**
 * 导出权限数据
 * @returns 导出的文件
 */
export const exportPermissionData = async (): Promise<any> => await request.get("/permission/export", { responseType: "blob" });

/**
 * 获取权限详情
 * @param id 权限 ID
 * @returns 权限详情
 */
export const fetchPermissionById = async (id: number): Promise<any> => await request.get(`/permission/${id}`);
